layui.use('form', function () {
    var form = layui.form
        , layer = layui.layer;
});

function submitlogin() {

    var username = jQuery("#username").val();
    var password = jQuery("#password").val();
    var HHH = sessionStorage.getItem("HHH5")
    if (username.length === 0) {
        layer.tips("请输入账号", '#username', {
            tips: [1, "#0FA6D8"],
            tipsMore: !1,
            time: 2000
        });
        jQuery("#username").focus();
        return false;
    }
    if (password.length === 0) {
        layer.tips("请输入密码", '#password', {
            tips: [1, "#0FA6D8"],
            tipsMore: !1,
            time: 2000
        });
        jQuery("#password").focus();
        return false;
    }
    if (HHH === null) {
        layer.tips("请滑动验证码", '#dwd', {
            tips: [1, "#0FA6D8"],
            tipsMore: !1,
            time: 2000
        })
        jQuery("#dwd").focus();
        return false;
    }


    var object = new Object(); //创建一个存放数据的对象
    object["username"] = username;
    object["password"] = password;
    var jsonData = JSON.stringify(object); //根据数据生成json数据
    jQuery.ajax({
        url: basePath + "/login",
        data: jsonData,
        contentType: "application/json;charset=UTF-8", //发送数据的格式
        type: "post",
        dataType: "json", //回调
        beforeSend: function () {
            layer.msg('登陆中', {
                icon: 16
                , shade: 0.01
            });
        },
        complete: function () {
            layer.closeAll('loading');
        },
        success: function (data) {
            if (data.status != 200) {
                if (data.status == 266) {
                    layer.msg(data.message, {
                        time: 1000,
                        icon: 1,
                        offset: '350px'
                    }, function () {
                        location.href = basePath + "/homePage";//成功登录后转跳的页面
                    });
                } else {
                    layer.msg(data.message, {
                        time: 1500,
                        icon: 2,
                        offset: '350px'
                    });
                }
            } else {
                layer.msg(data.message, {
                    time: 1000,
                    icon: 1,
                    offset: '350px'
                }, function () {
                    location.href = basePath + "/homePage";//成功登录后转跳的页面
                });
            }
        }
    });
}


var app = new Vue({
    el: '#app',
    data() {
        return {
            isHidden: 0,
            dataForm: {
                username: '',
                aiName: '',
                password: '',
                cpassword: ''
            }
        }

    },
    mounted: function () {

    },
    methods: {
        submitregister: function () {
            if (this.dataForm.username.length === 0) {
                layer.tips("请输入账号", '#uname', {
                    tips: [1, "#0FA6D8"],
                    tipsMore: !1,
                    time: 2000
                });
                jQuery("#uname").focus();
                return false;
            }
            if (this.dataForm.aiName.length === 0) {
                layer.tips("请输入昵称", '#nickname', {
                    tips: [1, "#0FA6D8"],
                    tipsMore: !1,
                    time: 2000
                });
                jQuery("#nickname").focus();
                return false;
            }
            if (this.dataForm.password.length === 0) {
                layer.tips("请输入密码", '#pwd', {
                    tips: [1, "#0FA6D8"],
                    tipsMore: !1,
                    time: 2000
                });
                jQuery("#pwd").focus();
                return false;
            }
            if (this.dataForm.cpassword.length === 0) {
                layer.tips("请确认密码", '#cpwd', {
                    tips: [1, "#0FA6D8"],
                    tipsMore: !1,
                    time: 2000
                });
                jQuery("#cpwd").focus();
                return false;
            }
            if (this.dataForm.password != this.dataForm.cpassword) {
                layer.tips("密码不一致", '#cpwd', {
                    tips: [1, "#0FA6D8"],
                    tipsMore: !1,
                    time: 2000
                });
                jQuery("#cpwd").focus();
                return false;
            }
            jQuery.ajax({
                url: basePath + "/register",//回调网址
                data: JSON.stringify(this.dataForm),
                contentType: "application/json;charset=UTF-8", //发送数据的格式
                type: "post",
                dataType: "json", //回调
                success: function (data) {
                    if (data.status == 200) {
                        layer.msg(data.message, {
                            time: 1500,
                            icon: 1,
                            offset: '350px'
                        }, function () {
                            location.href = basePath + "/index";//成功登录后转跳的页面
                        });
                        this.dataForm.username = ''
                        this.dataForm.aiName = ''
                        this.dataForm.password = ''
                        this.dataForm.cpassword = ''
                    } else {
                        layer.msg("注册失败，请重试", {
                            time: 1500,
                            icon: 2,
                            offset: '350px'
                        });
                    }
                }
            });
        }
    }
})

function submitForget() {
    var myAccount = jQuery("#myAccount").val();
    var myName = jQuery("#myName").val();
    var myPassword = jQuery("#myPassword").val();
    var myPasswordI = jQuery("#myPasswordI").val();
    if (myAccount.length === 0) {
        layer.tips("请输入账号", '#myAccount', {
            tips: [1, "#0FA6D8"],
            tipsMore: !1,
            time: 2000
        });
        jQuery("#myAccount").focus();
        return false;
    }
    if (myName.length === 0) {
        layer.tips("请输入昵称", '#myName', {
            tips: [1, "#0FA6D8"],
            tipsMore: !1,
            time: 2000
        });
        jQuery("#myName").focus();
        return false;
    }
    if (myPassword.length === 0) {
        layer.tips("请输入新密码", '#myPassword', {
            tips: [1, "#0FA6D8"],
            tipsMore: !1,
            time: 2000
        });
        jQuery("#myPassword").focus();
        return false;
    }
    if (myPasswordI.length === 0) {
        layer.tips("请确认新密码", '#myPasswordI', {
            tips: [1, "#0FA6D8"],
            tipsMore: !1,
            time: 2000
        });
        jQuery("#myPasswordI").focus();
        return false;
    }
    if (myPasswordI != myPassword) {
        layer.tips("密码不一致", '#cpwd', {
            tips: [1, "#0FA6D8"],
            tipsMore: !1,
            time: 2000
        });
        jQuery("#cpwd").focus();
        return false;
    }

    var forget = new Object();
    forget["username"] = myAccount;
    forget["aiName"] = myName;
    forget["password"] = myPassword;
    var jData = JSON.stringify(forget);
    jQuery.ajax({
        url: basePath + "/forget",
        data: jData,
        contentType: "application/json;charset=UTF-8",
        type: "post",
        dataType: "json",
        beforeSend: function () {
            layer.msg('登陆中', {
                icon: 16
                , shade: 0.01
            });
        },
        complete: function () {
            layer.closeAll('loading');
        },
        success: function (data) {
            if (data.status = 200) {
                layer.msg(data.message, {
                    time: 1000,
                    icon: 1,
                    offset: '350px'
                }, function () {
                    location.href = basePath + "/index";//成功登录后转跳的页面
                });
            } else {
                layer.msg(data.message, {
                    time: 1000,
                    icon: 1,
                    offset: '350px'
                }, function () {
                    location.href = "#";//成功登录后转跳的页面
                });
            }


        }
    });
}